//
//  UserViewController.m
//  DouBan
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 zuzhiming. All rights reserved.
//

#import "UserViewController.h"
#import "UserTableViewCell.h"
#import "LoginViewController.h"
@interface UserViewController ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, retain) UITableView *userTableView;
@property (nonatomic, retain) NSMutableArray *textArray;
@end

@implementation UserViewController
static NSString *const userTableViewCell = @"userTableViewCell";

- (void)dealloc
{
    [_userTableView release];
    [super dealloc];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self dataHandle];
    
    [self createUserTableView];
    
    [self createRightBarButtonItem];
}


- (void)dataHandle
{
    NSArray *array = @[@"     我的活动", @"     我的电影", @"     清除缓存"];
    self.textArray = [NSMutableArray arrayWithArray:array];
    
}

- (void)createRightBarButtonItem
{
    UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"注销" style:UIBarButtonItemStylePlain target:self action:@selector(didClickedButton:)];
    self.navigationItem.rightBarButtonItem = button;
}

- (void)didClickedButton:(UIBarButtonItem *)button
{
    NSLog(@"注销");
}
- (void)createUserTableView
{
    self.userTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - 44) style:UITableViewStylePlain];
    self.userTableView.backgroundColor = [UIColor whiteColor];
    //去除分割线
    self.userTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.userTableView.delegate = self;
    self.userTableView.dataSource = self;
    
    [self.userTableView registerClass:[UserTableViewCell class] forCellReuseIdentifier:userTableViewCell];
    
    [self.view addSubview:_userTableView];
    [_userTableView release];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 60;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.textArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
   UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:userTableViewCell forIndexPath:indexPath];
    
    cell.contentLabel.text = [self.textArray objectAtIndex:indexPath.row];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //第三行不能被点击
    if (indexPath.row == 2) {
        NSLog(@"%d %s", __LINE__, __FUNCTION__);
        return;
    }
    LoginViewController *login = [[LoginViewController alloc] init];
    [self.navigationController pushViewController:login animated:YES];
    [login release];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
